/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CRUD;

import Beans.BeanTela;
import Conexao.ConexaoBanco;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Marcos
 */
public class CRUDTela {
    
    public Connection conexao;

    public CRUDTela() throws SQLException {
        this.conexao = ConexaoBanco.getConexao();
    }    
    
    public List<BeanTela> getListaTela() throws SQLException {
        String sql = "select * from telas ";   

        PreparedStatement stmt = this.conexao.prepareStatement(sql);
        //stmt.setInt(1, cod_usuario);
        //stmt.setString(2, nome);
        ResultSet rs = stmt.executeQuery();
        List<BeanTela> ListaTela = new ArrayList<BeanTela>();
        while (rs.next()) {
            BeanTela BT = new BeanTela();
            BT.setCod_tela(rs.getInt("cod_tela"));            
            BT.setDen_tela(rs.getString("den_tela"));
            ListaTela.add(BT);
        }
        rs.close();
        stmt.close();
        return ListaTela;
    }
    public List<BeanTela> getListaTelaNom(String den_tela) throws SQLException {
        String sql = "select * from telas "
                + "where den_tela = ?";   

        PreparedStatement stmt = this.conexao.prepareStatement(sql);
        stmt.setString(1, den_tela);
        ResultSet rs = stmt.executeQuery();
        List<BeanTela> ListaTela = new ArrayList<BeanTela>();
        while (rs.next()) {
            BeanTela BT = new BeanTela();
            BT.setCod_tela(rs.getInt("cod_tela"));            
            BT.setDen_tela(rs.getString("den_tela"));
            ListaTela.add(BT);
        }
        rs.close();
        stmt.close();
        return ListaTela;
    }    
}